var util = require('../../../utils/util.js');
var apiObject = require('../../../utils/api.js');
var timer;

Page({

  data: {
    imgUrls: ["/image/carousel/1.png", "/image/carousel/1.png"],
    viewWidth: "",    //屏幕宽度
    imgheights:[],
    current:0,
    warning:true,
    warningImg:"/image/home/warning.png"
  },

  onShow: function (e) {
    var that = this;
    var clock = 0;
    that.setData({
      warningImg: "/image/home/warning.png"
    })
    clearInterval(timer);


    util.request(apiObject.api.checkFarmStatus).then(function (res) {
      if (res.code == 200) {
        that.setData({
          warning: res.result.warning
        })

        if (that.data.warning) {
          timer = setInterval(function () {
            clock++;
            if (clock % 2 == 1) {
              that.setData({
                warningImg: "/image/home/warning2.png"
              })
            } else {
              that.setData({
                warningImg: "/image/home/warning.png"
              })
            }
          }, 800);
        }
      } else {
        util.showModal(res.message);
      }
    })


   

  },
  redirectToWarning:function(){
    wx.switchTab({
      url: '../../warning/main/index',
    })
  },
  redirectToFarm:function(){
    wx.switchTab({
      url: '../../farm/main/index',
    })
  }
   

})